package com.demo.controller.airroute;

import com.demo.common.model.Aircraft;
import com.demo.common.model.Airroute;
import com.demo.common.model.Flighttime;
import com.demo.service.AircraftService;
import com.demo.service.AirrouteService;
import com.jfinal.aop.Inject;
import com.jfinal.core.Controller;
import com.jfinal.validate.Validator;


//航线验证
public class AirrouteValidator extends Validator {

    @Inject
    AirrouteService airrouteService;

    @Override
    protected void validate(Controller controller) {
        validateRequiredString("airroute.airrouteno", "airroutenoMsg", "请输入航线编号!");
        validateRequiredString("airroute.begin", "beginMsg", "请输入航线起点!");
        validateRequiredString("airroute.end", "endMsg", "请输入航线终点!");
        validateRequiredString("airroute.distance", "distanceMsg", "请输入距离路程!");

        String id=controller.getPara("airroute.id");
        String airrouteno=controller.getPara("airroute.airrouteno");
        if(airrouteService.findByAirrouteno(id,airrouteno)!=null){
            addError("airroutenoMsg", "航线编号已被添加，请使用别的航线编号！");
        }
    }

    @Override
    protected void handleError(Controller controller) {
        controller.keepModel(Airroute.class);

        String actionKey = getActionKey();
        if (actionKey.equals("/airroute/save"))
            controller.render("add.html");
        else if (actionKey.equals("/airroute/update"))
            controller.render("edit.html");
    }
}
